package net.ddns.xcyyds.kungfu.procedures;

import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.Entity;
import net.minecraft.network.chat.TextComponent;

import net.ddns.xcyyds.kungfu.network.KungFuModVariables;

public class JiChuQingGongBookUseProcedure {
	public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) {
		if (entity == null)
			return;
		if ((entity.getCapability(KungFuModVariables.PLAYER_VARIABLES_CAPABILITY, null)
				.orElse(new KungFuModVariables.PlayerVariables())).qingGong == 1) {
			{
				double _setval = 0;
				entity.getCapability(KungFuModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
					capability.qingGong = _setval;
					capability.syncPlayerVariables(entity);
				});
			}
			if (entity instanceof Player _player && !_player.level.isClientSide())
				_player.displayClientMessage(new TextComponent("\u4F60\u7684\u8F7B\u529F\u5DF2\u7ECF\u88AB\u6539\u4E3A\u201C\u65E0\u201D"), (false));
			SoundProcedure.execute(world, x, y, z, 1f, 1.5f);
		} else {
			{
				double _setval = 1;
				entity.getCapability(KungFuModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
					capability.qingGong = _setval;
					capability.syncPlayerVariables(entity);
				});
			}
			if (entity instanceof Player _player && !_player.level.isClientSide())
				_player.displayClientMessage(
						new TextComponent("\u4F60\u7684\u8F7B\u529F\u5DF2\u7ECF\u88AB\u6539\u4E3A\u201C\u57FA\u7840\u8F7B\u529F\u201D"), (false));
			SoundProcedure.execute(world, x, y, z, 1f, 1.5f);
		}
		ForSoundProcedure.execute(world, x, y, z);
	}
}
